package com.ruoyi.app.controller.project;

import com.ruoyi.app.business.project.FavouriteBusiness;
import com.ruoyi.app.config.annotation.OperationAuth;
import com.ruoyi.app.domain.project.ProjectSimple;
import com.ruoyi.app.domain.project.favoirite.FavouriteSave;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.project.query.FavouriteBaseQuery;
import com.ruoyi.service.user.enums.UserTypeEnum;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 收藏管理
 *
 * @author Zane
 * @since 2025-10-10
 */
@OperationAuth({UserTypeEnum.LABOR_USER})
@RestController
@RequestMapping("/project/favourite/")
public class FavouriteController {

  @Resource
  private FavouriteBusiness favouriteBusiness;

  /**
   * 收藏项目列表
   */
  @PostMapping("list")
  public TableDataInfo<ProjectSimple> favouriteList(@Validated @RequestBody FavouriteBaseQuery query) {
    CommonPageInfo<ProjectSimple> favouriteList = favouriteBusiness.favouriteList(query);
    return CommonUtils.buildTableData(favouriteList);
  }

  /**
   * 收藏或取消
   */
  @PostMapping("preferFavourite")
  public APIResult<Void> preferFavourite(@Validated @RequestBody FavouriteSave favouriteSave) {
    favouriteBusiness.preferFavourite(favouriteSave);
    return APIResult.success();
  }
}
